package com.comdo.newup_loan.module.setting;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.comdo.newup_loan.R;
import com.comdo.newup_loan.base.BaseActivity;
import com.comdo.newup_loan.comom.Config;
import com.comdo.newup_loan.util.StringUtils;
import com.comdo.newup_loan.util.TitleMenuUtil;

import butterknife.BindView;

/**
 * Created by liyuan on 2017/11/24.
 */

public class MofityPassActivity extends BaseActivity<MofityPassPresenter> implements MofityPassContract.View {
    @BindView(R.id.ed_pass)
    EditText mPassEdText;
    @BindView(R.id.ed_pass_new)
    EditText mNewPassEdText;
    @BindView(R.id.btn_submit)
    Button mSubmitBtn;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_mofity_pass;
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        new TitleMenuUtil(MofityPassActivity.this, "修改密码", false);
        mSubmitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (StringUtils.isNull(mPassEdText.getText().toString())) {
                    showToast("请输入新密码!");
                    return;
                }
                if (StringUtils.isNull(mNewPassEdText.getText().toString())) {
                    showToast("请确认新密码!");
                    return;
                }
                if (!mPassEdText.getText().toString().equals(mNewPassEdText.getText().toString())) {
                    showToast("两次密码不一致!");
                    return;
                }
                if ((mNewPassEdText.length() < 6 || mNewPassEdText
                        .length() > 16)) {
                    showToast("密码为6-16位!");
                    return;
                }
                if (!StringUtils.checkPassWordMix(mNewPassEdText.getText().toString())) {
                    showToast("密码必须为6到16位且必须由英文数字组合!");
                    return;
                }
                mPresenter.mofity(Config.loginInfo.getUserId(), StringUtils.Md5(mNewPassEdText.getText().toString()));
            }
        });

    }

    @Override
    public void mofity(String result) {
        showToast(result);
    }

    @Override
    public void Fail(String failMessage) {
        showToast(failMessage);
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
    }

    @Override
    public MofityPassPresenter getmPresenter() {
        return new MofityPassPresenter();
    }

    @Override
    public void presenterSetView() {
        if (mPresenter != null)
            mPresenter.setView(this);
    }
}
